/** 
 * Plogger.java Created by iweerarathna on Aug 31, 2011.
 * 
 * Copyright (c) 2011 Virtusa Corporation. All Rights Reserved.<br><br>. 
 * 
 */
package org.uim.cricket.storage;

import org.apache.log4j.*;
/**
 * @version 
 * @author iweerarathna
 */
public class Dlogger {

    private static Logger log;
    private static boolean isDebug = false;
    private static boolean isInfo = false;
    
    static {
        log = Logger.getLogger(Dlogger.class);
        PropertyConfigurator.configure("../config/logger.properties");
        isDebug = log.isDebugEnabled();
        isInfo = log.isInfoEnabled();
    }
    
    public static void debug(Object message) {
        if (isDebug) {
            log.debug(message);
        }
    }
    
    public static void debug(Object message, Exception e) {
        if (isDebug) {
            log.debug(message, e);
        }
    }
    
    public static void info(Object message) {
        if (isInfo) {
            log.info(message);
        }
    }
    
    public static void error(Object message) {
        log.error(message);
    }
    
    public static void error(Object message, Exception e) {
        log.error(message , e);
    }
    
    public static void warn(Object message) {
        log.warn(message);
    }
    
    public static void warn(Object message, Exception e) {
        log.warn(message, e);
    }
    
    public static void printHeader(Object message) {
        debug(repeat("-", 50));
        debug(message);
        debug(repeat("-", 50));
    }
    
    public static void printSubHeader(Object message) {
        debug(repeat(".", 50));
        debug(message);
        debug(repeat(".", 50));
    }
    
    public static String repeat(String s, int count) {
        StringBuilder sb = new StringBuilder();
        for (int i=0;i<count;i++) {
            sb.append(s);
        }
        return sb.toString();
    }
    
    public static void printHardWarn(Object message) {
        warn(repeat("*", 10) + message + repeat("*", 10));
    }
}
